home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome_100_percent.pak / Unnamed File 000029.txt < prev    next >
Text File  |  2013-04-03  |  2KB  |  64 lines

  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. // Custom bindings for the experimental offscreenTabs API.
  6.  
  7. (function() {
  8.  
  9. native function GetChromeHidden();
  10.  
  11. GetChromeHidden().registerCustomHook(
  12.     'experimental.offscreenTabs', function(api) {
  13.   var apiFunctions = api.apiFunctions;
  14.  
  15.   function maybeCopy(src, prop, dest) {
  16.     if (src[prop] !== undefined)
  17.       dest[prop] = src[prop];
  18.   };
  19.  
  20.   function keyboardEventFilter(e) {
  21.     var result = {
  22.       type: e.type,
  23.       ctrlKey: e.ctrlKey,
  24.       shiftKey: e.shiftKey,
  25.       altKey: e.altKey,
  26.       metaKey: e.metaKey,
  27.     };
  28.     maybeCopy(e, 'keyCode', result);
  29.     maybeCopy(e, 'charCode', result);
  30.     return result;
  31.   };
  32.  
  33.   function mouseEventFilter(e) {
  34.     var result = {
  35.       type: e.type,
  36.       ctrlKey: e.ctrlKey,
  37.       shiftKey: e.shiftKey,
  38.       altKey: e.altKey,
  39.       metaKey: e.metaKey,
  40.       button: e.button,
  41.     };
  42.     maybeCopy(e, 'wheelDeltaX', result);
  43.     maybeCopy(e, 'wheelDeltaY', result);
  44.     return result;
  45.   };
  46.  
  47.   // We are making a copy of |arr|, but applying |func| to index 1.
  48.   function validate(arr, func) {
  49.     var newArr = [];
  50.     for (var i = 0; i < arr.length; i++)
  51.       newArr.push(i == 1 && typeof(arr) == 'object' ? func(arr[i]) : arr[i]);
  52.     return newArr;
  53.   }
  54.  
  55.   apiFunctions.setUpdateArgumentsPreValidate(
  56.       'sendKeyboardEvent',
  57.       function() { return validate(arguments, keyboardEventFilter); });
  58.   apiFunctions.setUpdateArgumentsPreValidate(
  59.       'sendMouseEvent',
  60.       function() { return validate(arguments, mouseEventFilter); });
  61. });
  62.  
  63. })();
  64.